#include "player.h"

Player::Player()
{
    jump=2;
    vx=vy=0;
    move=shoot=leftMove=rightMove=0;
}//构造函数进行初始化

void Player::MoveLeft(){
    leftMove=true;
    move=true;
}
void Player::MoveRight(){
    rightMove=true;
    move=true;
}

void Player::StopLeft(){
    leftMove=false;
    move=false;
}
void Player::StopRight(){
    rightMove=false;
    move=false;
}
//设置向左、向右移动的相关x轴方向的速度变化

void Player::trulyMoveLeft(){if (leftMove) vx-=2; if (vx<-12) vx=-12;}
void Player::trulyMoveRight(){if (rightMove) vx+=2; if (vx>12) vx=12;}
void Player::stopMoveX(){vx=0;}


//设置击球相关函数
void Player::Shoot(){shoot=true;}
bool Player::checkShoot(){return shoot;}
void Player::StopShoot(){shoot=false;}



int &Player::x(){return px;}
int &Player::y(){return py;}


//更新击球人的位置
void Player::updatePosition(){
    py+=vy;
    px+=vx;
    if (py<805){
        vy+=1.2;
    }else{
        vy=0;
        py=805;
        jump=2;
        if (!move){
            if (vx>1.2) vx-=1.2;
            else if (vx<-1.2) vx+=1.2;
            else vx=0;
        }
    }
}

//设置跳跃时位置坐标的变化
void Player::Jump(){
    if (jump>0){
        vy-=20;
        if (vy<-30) vy=-30;
        jump--;
    }
}
void Player::setJump(){jump=2;vy=0;}

//对击球者的位置进行初始化
void Player::reset(){
    jump=2;
    vx=vy=0;
    move=shoot=leftMove=rightMove=0;
    py=805;
}
